package www.golf.web;

import java.sql.Array;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.postgresql.jdbc4.Jdbc4Array;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Panel;
import org.zkoss.zul.Window;

import www.golf.ibatis.IBatisFactory;
import www.golf.web.session.WebSession;
import www.golf.web.util.UtilZKObject;

public class LoginControl extends WebSession {
	UtilZKObject zkObject =new UtilZKObject(this);
	public void initialize() {
	}
	
	public void login(){
		Map map= new HashMap();
		map.put("id", zkObject.getValue("accountID"));
		map.put("pwd", zkObject.getValue("accountPWD"));
		Object t = null;
		try {
			t = (Object)dbSession().queryForObject("User.checkedUser", map);
			dbSessionClose();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if(t!=null){
			setLoginSession(String.valueOf(map.get("id")), String.valueOf(map.get("pwd")),
					(Integer)((Map)t).get("pid"),(Array)((Map)t).get("job_id")
					,((Array)((Map)t).get("group_id")),(Integer)((Map)t).get("power"));
			//Executions.createComponents("./main/main.zul", null, null);
			Executions.getCurrent().sendRedirect("./main/main.zul");
			//this.getParent().getChildren().remove(this);
			this.detach();
		}else{
			try {
				Messagebox.show("帐号密码错误!!");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
